import { jsonEach } from "~utils/shared/cstor";

/**
 * 对一个对象执行清空合并操作
 * @param reactive 一个对象
 * @param v 执行clear
 */
export function mergeReactive<T extends Dict = Dict>(reactive: T, merged: T = ({} as T)) {
  jsonEach(reactive, key => {
    reactive[key] = merged?.hasOwnProperty(key) ? merged[key] : null as T[keyof T];
  });
}

export function clearReactive<T extends Dict = Dict>(reactive: T, m?) {
  jsonEach(reactive, key => {
    reactive[key] = (m ?? null) as any;
  });
}